package com.ruoyi.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WmsInbound;
import com.ruoyi.system.service.IWmsInboundService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库信息Controller
 *
 * @author ruoyi
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/system/wmsInbound")
public class WmsInboundController extends BaseController {

    @Autowired
    private IWmsInboundService wmsInboundService;

    /**
     * 查询入库信息列表
     */
    @SaCheckPermission("system:wmsInbound:list")
    @GetMapping("/list")
    public TableDataInfo<WmsInbound> list(WmsInbound wmsInbound, PageQuery pageQuery) {
        return wmsInboundService.selectWmsInboundList(wmsInbound, pageQuery);
    }

    /**
     * 导出入库信息列表
     */
    /*@SaCheckPermission("system:wmsInbound:export")
    @Log(title = "入库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInbound wmsInbound) {
        List<WmsInbound> list = wmsInboundService.selectWmsInboundList(wmsInbound);
        ExcelUtil.exportExcel(list, "入库信息", WmsInbound.class, response);
    }*/

    /**
     * 获取入库信息详细信息
     */
    @SaCheckPermission("system:wmsInbound:query")
    @GetMapping(value = "/{id}")
    public R<WmsInbound> getInfo(@PathVariable("id") Long id) {
        return R.ok(wmsInboundService.selectWmsInboundById(id));
    }

    /**
     * 新增入库信息
     */
    @SaCheckPermission("system:wmsInbound:add")
    @Log(title = "入库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@RequestBody WmsInbound wmsInbound) throws Exception {
        return toAjax(wmsInboundService.insertWmsInbound(wmsInbound));
    }

    /**
     * 修改入库信息
     */
    @SaCheckPermission("system:wmsInbound:edit")
    @Log(title = "入库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody WmsInbound wmsInbound) throws Exception {
        return toAjax(wmsInboundService.updateWmsInbound(wmsInbound));
    }

    /**
     * 删除入库信息
     */
    @SaCheckPermission("system:wmsInbound:remove")
    @Log(title = "入库信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(wmsInboundService.deleteWmsInboundByIds(ids));
    }

    /**
     * 获取入库单号
     */
    @SaCheckPermission("system:wmsInbound:query")
    @GetMapping("/getInboundOrderNo")
    public R<WmsInbound> getInboundOrderNo() {
        return R.ok(wmsInboundService.getInboundOrderNo());
    }

    /**
     * 取消入库单号
     */
    @SaCheckPermission("system:wmsInbound:clearOrderNo")
    @GetMapping("/clearOrderNo")
    public R<Void> clearOrderNo() {
        wmsInboundService.clearOrderNo();
        return R.ok();
    }
}
